fix: rna2vec case-insensitivity for secondary structures#608
Open
agam263 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Silent Data Corruption in
rna2vecdue to Case Sensitivityfix #606
📖 Summary
This PR resolves a critical bug in the
rna2vecutility function where secondary structure sequences were processed in a case-sensitive manner. This caused any lowercase input to fail triplet matching silently, returning vectors populated entirely by zeros.🔍 Technical Root Cause
The
rna2vecfunction transforms biological sequences into numerical representations by extracting overlapping triplets and mapping them to indices via a pre-generated vocabulary.dna2rna(), secondary structure (SS) sequences were taken directly from the input.S, H, M, I, B, X, E). When a user provided a lowercase sequence like"sshh", the triplet lookuptriplets.get("ssh", 0)would fail to find a match and default to0(the padding index).🛠️ Proposed Changes
1. Robust Normalization
Updated the core loop in
pyaptamer/utils/_rna.pyto enforce.upper()normalization on every sequence at the start of the iteration. This ensures that:2. Regression Testing
Introduced a new test file:
pyaptamer/utils/tests/test_rna2vec_robustness.py.SSHH) and lowercase (sshh) inputs yield identical, non-zero NumPy arrays.✅ Verification Results
pytest pyaptamer/utils/tests/test_rna2vec_robustness.py-> Passed.pytest pyaptamer/utils/tests/test_rna.py-> Passed.